package com.shuzixiangcun.controller.admin;

import com.github.pagehelper.PageInfo;
import com.shuzixiangcun.entity.EnterpriseCertification;
import com.shuzixiangcun.entity.HealthRecords;
import com.shuzixiangcun.service.admin.EnterpriseCertificationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 企业认证信息表(EnterpriseCertification)表控制层
 *
 * @author makejava
 * @since 2024-06-24 10:38:14
 */
@RestController
@RequestMapping("admin/enterpriseCertification")
@CrossOrigin
public class EnterpriseCertificationController {
    /**
     * 服务对象
     */
    @Resource
    private EnterpriseCertificationServiceImpl enterpriseCertificationService;

    @Autowired
    private EnterpriseCertificationServiceImpl enterpriseCertificationServiceImpl;

    @Value("${file.save-path}")
    private  String savePath;
    /**
     * 上传
     * @param multipartFile
     * @return
     */

    @PostMapping(value = "/upload")
    public ResponseEntity upLoadFiles(@RequestParam("multipartFile") MultipartFile multipartFile, HttpServletRequest request) {
        if (multipartFile.isEmpty()){
            return ResponseEntity.status(500).header("Custom-Header", "foo")
                    .body("文件不能为空！");
        }
        return enterpriseCertificationServiceImpl.upLoadFiles(savePath,multipartFile,request);
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<EnterpriseCertification> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.enterpriseCertificationService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param enterpriseCertification 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<EnterpriseCertification> add(EnterpriseCertification enterpriseCertification) {
        return ResponseEntity.ok(this.enterpriseCertificationService.insert(enterpriseCertification));
    }




    /**
     * 编辑数据
     *
     * @param enterpriseCertification 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<EnterpriseCertification> edit(EnterpriseCertification enterpriseCertification) {
        return ResponseEntity.ok(this.enterpriseCertificationService.update(enterpriseCertification));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("deleteById")
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.enterpriseCertificationService.deleteById(id));
    }

    @GetMapping("/PageInfo")
    public ResponseEntity<PageInfo<EnterpriseCertification>> getJobApplicationsList(@RequestParam Integer pageNo, @RequestParam Integer pageSize){

        return ResponseEntity.ok(this.enterpriseCertificationService.getPageInfo(pageNo,pageSize));
    }

    @PostMapping("updateByState")
    public ResponseEntity updateByState(EnterpriseCertification enterpriseCertification){
        String state1=enterpriseCertification.getState().equals("Y")?"N":"Y";

        enterpriseCertification.setState(state1);
        if (this.enterpriseCertificationService.updateByState(enterpriseCertification)>0){
            return ResponseEntity.status(200).header("Custom-Header", "foo")
                    .body("修改成功");
        }
        return ResponseEntity.status(500).header("Custom-Header", "foo")
                .body("修改失败");
    }
}

